<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>班级管理系统</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/js/jquery.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">班级系统管理</div>
        <ul class="layui-nav layui-layout-left">
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="${session.user.img}" class="layui-nav-img">
                    <span id="username" th:text="${session.username}"></span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="/user/center">基本资料</a></dd>
                    <dd><a href="/user/password">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="/logout">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test" id="baseMenu">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">管理员</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/menu/studentManager">学生信息管理</a></dd>
                        <dd><a href="/menu/teacherManager">老师信息管理</a></dd>
                        <dd><a href="/menu/classManager">班级信息管理</a></dd>
                        <dd><a href="/menu/checkManager">考勤信息管理</a></dd>
                    </dl>
                </li>
<!--                <li class="layui-nav-item">-->
<!--                    <a href="javascript:;">解决方案</a>-->
<!--                    <dl class="layui-nav-child">-->
<!--                        <dd><a href="javascript:;">列表一</a></dd>-->
<!--                        <dd><a href="javascript:;">列表二</a></dd>-->
<!--                        <dd><a href="">超链接</a></dd>-->
<!--                    </dl>-->
<!--                </li>-->
<!--                <li class="layui-nav-item"><a href="">云市场</a></li>-->
<!--                <li class="layui-nav-item"><a href="">发布商品</a></li>-->
            </ul>
        </div>
    </div>

    <div class="layui-body" >
        <!-- 内容主体区域 -->
        <iframe name="mainFrame"  style="width: 100%;height: 98%" frameborder="0"></iframe>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © ATM - 底部固定区域
    </div>
</div>
<script src="/layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
    });
</script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
        element.render('tab', 'demo-filter-tab'); //开启选项卡功能
        $(function (){
            //菜单初始化
            function initMenu(){
                $.get("/menu/list",function (data){
                    if(data.code==200){
                        let menuList = data.data;
                        let baseMenu = $("#baseMenu");
                        baseMenu.html("");
                        for(let i=0;i<menuList.length;i++){
                            let menu = menuList[i];
                            let menus=menu.children;
                            let murl=menu.murl;
                            let myclass='myMenu';
                            if (murl=='/'){
                                myclass='';
                            }
                            let html=`<li class="layui-nav-item layui-nav-itemed">
                            <a class="${myclass}" href="javascript:;" xid="${menu.mid}" value="${menu.murl}">${menu.mname}</a>
                            <dl class="layui-nav-child">
                        `
                            for(let j=0;j<menus.length;j++){
                                let menu2=menus[j];
                                let murl=menu2.murl;
                                let myclass='myMenu2';
                                if (murl=='/'){
                                    myclass='';
                                }
                                html+=`<dd><a class="${myclass}" xid="${menu2.mid}" href="${menu2.murl}" value="${menu2.murl}" target="mainFrame" ">${menu2.mname}</a></dd>`
                            }
                            html+=`</dl></li>`
                            baseMenu.append(html);
                            element.render('nav');
                            $(".myMenu2,.myMenu").click(function () {
                                let mid=$(this).attr("xid");
                                let murl=$(this).attr("value");
                                let title=$(this).text();
                                let flag=$("#myTab").find("li[lay-id='"+mid+"']").length>0;
                                if(flag){
                                    element.tabChange('demo-filter-tab',mid);
                                }else {
                                    $.get(murl,function (data){
                                        flag=$("#myTab").find("li[lay-id='"+mid+"']").length>0;
                                        if(!flag){
                                            element.tabAdd('demo-filter-tab',{
                                                title:title,
                                                content:`${data}`,
                                                id:mid,
                                                allowClose:true,
                                                change:true
                                            })
                                            element.tabChange('demo-filter-tab',mid);
                                        }
                                    })
                                }
                            });
                        }
                    }
                })
            }
            initMenu();
            $("#username").html(localStorage.getItem("username"))
        })
    });
</script>
</body>
</html>